package day12.network;

import java.io.*;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.sql.SQLOutput;
import java.util.Scanner;

public class Client1 {
    public static void main(String[] args) throws IOException {
        //如果不出异常，就已经建立了连接通道
        Socket s = new Socket("127.0.0.1", 8000);
//        InputStream in = s.getInputStream();
//        OutputStream out = s.getOutputStream();
//
//        out.write("hello".getBytes());

//        for (int i = 0; i < 5; i++) {
//            char c = (char) in.read();
//            System.out.print(c);
//        }
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));

        while(true){
            System.out.print(">>");
            String response = new Scanner(System.in).nextLine();
            if("exit".equals(response)){
                s.close();
                break;
            }
            out.println(response);
            out.flush();

            String line = in.readLine();
            System.out.println(line);
        }




    }
}
